<template>
  <div class="holographic-login-wrap">
    <!-- 全息背景 -->
    <div class="holographic-bg">
      <div class="holographic-grid"></div>
      <div class="scan-lines"></div>
      <div class="holographic-particles">
        <div class="particle" v-for="i in 30" :key="i"></div>
      </div>
      <div class="neon-rings">
        <div class="ring ring-1"></div>
        <div class="ring ring-2"></div>
        <div class="ring ring-3"></div>
      </div>
    </div>

    <div class="login-container">
      <div class="login-panel">
        <!-- 全息边框 -->
        <div class="panel-border panel-border-top"></div>
        <div class="panel-border panel-border-right"></div>
        <div class="panel-border panel-border-bottom"></div>
        <div class="panel-border panel-border-left"></div>
        
        <div class="panel-header">
          <div class="logo-section">
            <div class="holographic-logo">
              <div class="logo-hologram">
                <div class="hologram-layer hologram-layer-1"></div>
                <div class="hologram-layer hologram-layer-2"></div>
                <div class="hologram-layer hologram-layer-3"></div>
                <div class="logo-text">ERP</div>
              </div>
              <div class="logo-scanline"></div>
            </div>
            <h2 class="holographic-title">
              <span class="title-line">管理系统</span>
            </h2>
            <p class="holographic-subtitle">
              <span class="subtitle-glow">欢迎进入未来</span>
            </p>
          </div>
        </div>

        <el-form
          ref="loginFormRef"
          :model="loginForm"
          :rules="loginRules"
          class="login-form"
          @submit.prevent="handleLogin"
        >
          <el-form-item prop="username">
            <div class="input-wrapper">
              <div class="input-label">用户名</div>
              <el-input
                v-model="loginForm.username"
                placeholder="Enter username"
                size="large"
                prefix-icon="User"
                class="holographic-input"
              />
              <div class="input-underline"></div>
            </div>
          </el-form-item>

          <el-form-item prop="password">
            <div class="input-wrapper">
              <div class="input-label">密码</div>
              <el-input
                v-model="loginForm.password"
                type="password"
                placeholder="Enter password"
                size="large"
                prefix-icon="Lock"
                class="holographic-input"
                show-password
              />
              <div class="input-underline"></div>
            </div>
          </el-form-item>

          <el-form-item>
            <div class="remember-forgot">
              <el-checkbox v-model="rememberMe" class="holographic-checkbox">
                <span>记住登录状态</span>
              </el-checkbox>
              <a class="holographic-link" @click="forgotPassword">
                <span>忘记密码?</span>
              </a>
            </div>
          </el-form-item>

          <el-form-item>
            <el-button
              type="primary"
              size="large"
              class="holographic-button"
              :loading="loading"
              @click="handleLogin"
            >
              <span class="button-content">
                <span class="button-text">登录</span>
                <span class="button-sparkle">✦</span>
              </span>
              <div class="button-border"></div>
            </el-button>
          </el-form-item>
        </el-form>

        <div class="panel-footer">
          <div class="footer-divider">
            <span></span>
            <span class="divider-text">OR</span>
            <span></span>
          </div>
          <p class="footer-text">
            还没有账号？
            <a class="holographic-link" @click="register">
              <span>立即注册</span>
            </a>
          </p>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { useUserStore } from '@/stores/user'

const router = useRouter()
const store = useUserStore()

const emit = defineEmits(['login'])

const loginFormRef = ref(null)
const loading = ref(false)
const rememberMe = ref(false)

const loginForm = reactive({
  username: '',
  password: ''
})

const loginRules = {
  username: [
    { required: true, message: '请输入用户名', trigger: 'blur' }
  ],
  password: [
    { required: true, message: '请输入密码', trigger: 'blur' },
    { min: 6, message: '密码长度不能少于6位', trigger: 'blur' }
  ]
}

const handleLogin = async () => {
  if (!loginFormRef.value) return

  try {
    await loginFormRef.value.validate()
    loading.value = true

    const response = await store.login(loginForm)

    if (response.code === 200) {
      ElMessage.success(response.msg || '登录成功')
      emit('login', response)
      router.push('/dashboard')
    } else {
      ElMessage.error(response.msg || '登录失败')
    }
  } catch (error) {
    console.error('登录失败:', error)
    ElMessage.error(error.message || '网络请求失败，请重试')
  } finally {
    loading.value = false
  }
}

const register = () => {
  ElMessage.info('注册功能开发中...')
}

const forgotPassword = () => {
  ElMessage.info('忘记密码功能开发中...')
}
</script>

<style scoped>
.holographic-login-wrap {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: radial-gradient(circle at center, #0a0e27 0%, #000000 100%);
}

/* 全息背景 */
.holographic-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

.holographic-grid {
  position: absolute;
  width: 100%;
  height: 100%;
  background-image: 
    linear-gradient(rgba(0, 245, 255, 0.1) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 245, 255, 0.1) 1px, transparent 1px);
  background-size: 60px 60px;
  animation: gridMove 30s linear infinite;
}

@keyframes gridMove {
  0% { transform: translate(0, 0); }
  100% { transform: translate(60px, 60px); }
}

.scan-lines {
  position: absolute;
  width: 100%;
  height: 100%;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 245, 255, 0.03) 2px,
    rgba(0, 245, 255, 0.03) 4px
  );
  animation: scanMove 8s linear infinite;
}

@keyframes scanMove {
  0% { background-position: 0 0; }
  100% { background-position: 0 100%; }
}

.holographic-particles {
  position: absolute;
  width: 100%;
  height: 100%;
}

.particle {
  position: absolute;
  width: 4px;
  height: 4px;
  background: #00f5ff;
  border-radius: 50%;
  box-shadow: 0 0 10px #00f5ff;
  animation: particleMove 20s infinite;
}

@keyframes particleMove {
  0% {
    transform: translate(0, 100vh);
    opacity: 0;
  }
  10% {
    opacity: 1;
  }
  90% {
    opacity: 1;
  }
  100% {
    transform: translate(100vw, -100vh);
    opacity: 0;
  }
}

.neon-rings {
  position: absolute;
  width: 100%;
  height: 100%;
}

.ring {
  position: absolute;
  border: 2px solid rgba(0, 245, 255, 0.2);
  border-radius: 50%;
  animation: ringPulse 4s ease-in-out infinite;
}

.ring-1 {
  width: 400px;
  height: 400px;
  top: -100px;
  left: -100px;
}

.ring-2 {
  width: 600px;
  height: 600px;
  bottom: -200px;
  right: -200px;
  animation-delay: 1.5s;
}

.ring-3 {
  width: 500px;
  height: 500px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation-delay: 3s;
}

@keyframes ringPulse {
  0%, 100% {
    transform: scale(1);
    opacity: 0.2;
  }
  50% {
    transform: scale(1.1);
    opacity: 0.4;
  }
}

/* 登录容器 */
.login-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.login-panel {
  position: relative;
  width: 480px;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(0, 245, 255, 0.3);
  padding: 60px 50px;
  box-shadow: 
    0 0 50px rgba(0, 245, 255, 0.2),
    inset 0 0 50px rgba(0, 245, 255, 0.05);
}

/* 全息边框 */
.panel-border {
  position: absolute;
  background: linear-gradient(
    to right,
    transparent,
    rgba(0, 245, 255, 0.5),
    transparent
  );
}

.panel-border-top {
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  animation: borderMove 3s linear infinite;
}

.panel-border-right {
  right: 0;
  top: 0;
  bottom: 0;
  width: 2px;
  animation: borderMove 3s linear infinite 1s;
}

.panel-border-bottom {
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  animation: borderMove 3s linear infinite 2s;
}

.panel-border-left {
  left: 0;
  top: 0;
  bottom: 0;
  width: 2px;
  animation: borderMove 3s linear infinite 3s;
}

@keyframes borderMove {
  0% { transform: scaleX(0); }
  50% { transform: scaleX(1); }
  100% { transform: scaleX(0); }
}

.panel-header {
  text-align: center;
  margin-bottom: 40px;
}

.logo-section {
  position: relative;
}

.holographic-logo {
  position: relative;
  width: 120px;
  height: 120px;
  margin: 0 auto 25px;
}

.logo-hologram {
  position: relative;
  width: 100%;
  height: 100%;
  perspective: 1000px;
}

.hologram-layer {
  position: absolute;
  width: 100%;
  height: 100%;
  border: 2px solid #00f5ff;
  border-radius: 50%;
  opacity: 0.3;
}

.hologram-layer-1 {
  animation: logoRotate 6s linear infinite;
}

.hologram-layer-2 {
  animation: logoRotate 4s linear infinite reverse;
  border-color: #00ff88;
}

.hologram-layer-3 {
  animation: logoRotate 8s linear infinite;
  border-color: #ff00ff;
  width: 80%;
  height: 80%;
  top: 10%;
  left: 10%;
}

@keyframes logoRotate {
  0% { transform: rotateY(0deg); }
  100% { transform: rotateY(360deg); }
}

.logo-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 36px;
  font-weight: bold;
  color: #00f5ff;
  text-shadow: 
    0 0 10px #00f5ff,
    0 0 20px #00f5ff,
    0 0 30px #00f5ff;
  z-index: 2;
}

.logo-scanline {
  position: absolute;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    to bottom,
    transparent 0%,
    rgba(0, 245, 255, 0.1) 50%,
    transparent 100%
  );
  animation: scanlineMove 2s linear infinite;
}

@keyframes scanlineMove {
  0% { transform: translateY(-100%); }
  100% { transform: translateY(100%); }
}

.holographic-title {
  font-size: 32px;
  font-weight: bold;
  margin: 0 0 10px;
}

.title-line {
  display: inline-block;
  color: #00f5ff;
  text-shadow: 
    0 0 10px #00f5ff,
    0 0 20px #00f5ff,
    0 0 30px #00f5ff;
  animation: textGlitch 3s infinite;
}

@keyframes textGlitch {
  0%, 90%, 100% { 
    transform: translate(0);
  }
  91% { 
    transform: translate(-2px, 2px);
    text-shadow: 0 0 10px #00f5ff, 0 0 20px #00ff88;
  }
  92% { 
    transform: translate(2px, -2px);
    text-shadow: 0 0 10px #ff00ff, 0 0 20px #00f5ff;
  }
  93% { 
    transform: translate(-2px, 2px);
  }
  94% { 
    transform: translate(2px, -2px);
  }
  95% { 
    transform: translate(0);
  }
}

.holographic-subtitle {
  font-size: 14px;
  margin: 0;
  letter-spacing: 3px;
}

.subtitle-glow {
  color: rgba(0, 245, 255, 0.8);
  text-shadow: 0 0 10px rgba(0, 245, 255, 0.5);
  animation: subtitlePulse 2s ease-in-out infinite;
}

@keyframes subtitlePulse {
  0%, 100% { opacity: 0.8; }
  50% { opacity: 1; }
}

/* 登录表单 */
.login-form {
  width: 100%;
}

.input-wrapper {
  position: relative;
  margin-bottom: 35px;
}

.input-label {
  color: #00f5ff;
  font-size: 14px;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 1px;
  text-shadow: 0 0 10px rgba(0, 245, 255, 0.5);
}

.holographic-input {
  width: 100%;
}

:deep(.el-input__wrapper) {
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(0, 245, 255, 0.3);
  box-shadow: none;
  transition: all 0.3s;
  border-radius: 0;
}

:deep(.el-input__wrapper:hover) {
  border-color: rgba(0, 245, 255, 0.6);
  box-shadow: 0 0 15px rgba(0, 245, 255, 0.3);
}

:deep(.el-input.is-focus .el-input__wrapper) {
  border-color: #00f5ff;
  box-shadow: 0 0 20px rgba(0, 245, 255, 0.5);
  background: rgba(0, 245, 255, 0.1);
}

:deep(.el-input__inner) {
  color: #00f5ff;
  background: transparent;
}

:deep(.el-input__inner::placeholder) {
  color: rgba(0, 245, 255, 0.5);
}

.input-underline {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0;
  height: 2px;
  background: linear-gradient(
    90deg,
    transparent,
    #00f5ff,
    transparent
  );
  transition: width 0.3s;
}

:deep(.el-input.is-focus ~ .input-underline) {
  width: 100%;
}

.remember-forgot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
}

.holographic-checkbox :deep(.el-checkbox__label) {
  color: rgba(255, 255, 255, 0.8);
  font-size: 14px;
}

.holographic-checkbox :deep(.el-checkbox__input.is-checked .el-checkbox__inner) {
  background-color: #00f5ff;
  border-color: #00f5ff;
  box-shadow: 0 0 10px rgba(0, 245, 255, 0.5);
}

.holographic-link {
  color: #00f5ff;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.3s;
  position: relative;
}

.holographic-link span {
  position: relative;
  z-index: 2;
}

.holographic-link::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0;
  height: 1px;
  background: #00f5ff;
  box-shadow: 0 0 5px #00f5ff;
  transition: width 0.3s;
}

.holographic-link:hover::after {
  width: 100%;
}

.holographic-link:hover {
  text-shadow: 0 0 10px #00f5ff;
}

/* 登录按钮 */
.holographic-button {
  width: 100%;
  height: 50px;
  background: linear-gradient(135deg, rgba(0, 245, 255, 0.3), rgba(0, 255, 136, 0.3));
  border: 2px solid #00f5ff;
  color: #00f5ff;
  font-size: 16px;
  font-weight: bold;
  letter-spacing: 2px;
  position: relative;
  overflow: hidden;
  transition: all 0.3s;
  box-shadow: 
    0 0 20px rgba(0, 245, 255, 0.3),
    inset 0 0 20px rgba(0, 245, 255, 0.1);
}

.holographic-button:hover {
  background: linear-gradient(135deg, rgba(0, 245, 255, 0.5), rgba(0, 255, 136, 0.5));
  box-shadow: 
    0 0 30px rgba(0, 245, 255, 0.6),
    inset 0 0 30px rgba(0, 245, 255, 0.2);
  transform: translateY(-2px);
}

.button-content {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.button-sparkle {
  animation: sparkle 1.5s ease-in-out infinite;
}

@keyframes sparkle {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.2); }
}

.button-border {
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.4),
    transparent
  );
  animation: buttonShine 3s linear infinite;
}

@keyframes buttonShine {
  0% { left: -100%; }
  100% { left: 100%; }
}

:deep(.holographic-button.is-loading) {
  pointer-events: none;
}

.panel-footer {
  text-align: center;
  margin-top: 30px;
}

.footer-divider {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
}

.footer-divider span {
  flex: 1;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(0, 245, 255, 0.3),
    transparent
  );
}

.divider-text {
  color: rgba(0, 245, 255, 0.8);
  padding: 0 15px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 2px;
}

.footer-text {
  color: rgba(255, 255, 255, 0.8);
  font-size: 14px;
}
</style>

